package com.netty.netty_webSocket;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * webSocket 是基于http协议的，可以实现长链接
 */

public class webSocketServer {

    public static void main(String[] args) throws InterruptedException {
        /**
         * 事件循环组
         */
        EventLoopGroup boosGroup = new NioEventLoopGroup();
        EventLoopGroup workGroup = new NioEventLoopGroup();

        try{
            /**
             * 创建和启动socketchannel
             */
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(boosGroup,workGroup).channel(NioServerSocketChannel.class).childHandler(new webSocketServerInitializer());
            /**
             * 绑定端口号，sync是必须要加的，它表示一直监听端口。
             */
            ChannelFuture channelFuture = serverBootstrap.bind(9999).sync();
            channelFuture.channel().closeFuture().sync();
        }finally {
            boosGroup.shutdownGracefully();
            workGroup.shutdownGracefully();
        }
    }

}
